package it.xiuxian.homepage.fragment

import android.annotation.SuppressLint
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import it.xiuxian.homepage.R
import it.xiuxian.homepage.bean.GongXian
import it.xiuxian.homepage.bean.MonGongXianBean
import it.xiuxian.homepage.databinding.HomepageGongxianNewFragmentBinding
import it.xiuxian.homepage.presenter.PaiHangBangFragmentPresenter
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseFragment
import it.xiuxian.lib.utils.ImageUtil
import it.xiuxian.lib.utils.adapter.SlimAdapter
import it.xiuxian.lib.utils.adapter.SlimInjector
import it.xiuxian.lib.utils.adapter.injector.IViewInjector

@Route(path = ArouterAddress.PAIHANGBANGFRAGMENT)
class PaiHangBangFragment:BaseFragment<PaiHangBangFragmentPresenter>() {
    @JvmField
    @Autowired
    var flag:String?=null
    lateinit var adapter1: SlimAdapter
    lateinit var binding:HomepageGongxianNewFragmentBinding
    override val layoutId: Int
        get() = R.layout.homepage_gongxian_new_fragment
    override val presenter: PaiHangBangFragmentPresenter
        get() = PaiHangBangFragmentPresenter()

    override fun isEmpty(textView: TextView?): Boolean {
        return false

    }
    var i =0
    override fun initView() {
        //super.initView()
        binding= getViewDataBinding<HomepageGongxianNewFragmentBinding>()
        ARouter.getInstance().inject(this)
        binding.rv.layoutManager = LinearLayoutManager(requireActivity())
        adapter1 = SlimAdapter.create().register<GongXian>(R.layout.homepage_gongxian_item,object :
            SlimInjector<GongXian> {
            @SuppressLint("UseCompatLoadingForDrawables")
            override fun onInject(data: GongXian?, injector: IViewInjector<out IViewInjector<*>>?) {

                injector!!.text(R.id.tv_name,data!!.nickname)
                    .text(R.id.tv_gongxianzhi,data.gongxianzhi)
                    ++i
                if(i==1){
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).visibility = View.VISIBLE
                    injector.visibility(R.id.tv_mingci,View.GONE)
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).setImageDrawable(resources.getDrawable(R.mipmap.homepage_one))
                }else if(i==2){
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).visibility = View.VISIBLE
                    injector.visibility(R.id.tv_mingci,View.GONE)
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).setImageDrawable(resources.getDrawable(R.mipmap.homepage_two))
                }else if(i==3){
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).visibility = View.VISIBLE
                    injector.visibility(R.id.tv_mingci,View.GONE)
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).setImageDrawable(resources.getDrawable(R.mipmap.homepage_three))
                }else{
                    (injector.findViewById<ImageView>(R.id.image_ming) as ImageView).visibility = View.GONE
                    injector.visibility(R.id.tv_mingci,View.VISIBLE).text(R.id.tv_mingci,i.toString())
                }
                ImageUtil.setCircleImage(data.faceurl, injector.findViewById<ImageView>(R.id.image) as ImageView)


            }

        }).attachTo(binding.rv)
    }

    override fun initData() {
        //super.initData()
        if (flag=="1"){
            mPresenter!!.getMonGongxian()
        }else{
            mPresenter!!.getZongGongxian()
        }
    }
    fun setGongXian(data: MonGongXianBean) {
        adapter1.updateData(data.list)
    }

    fun setZong(data: MonGongXianBean) {
        adapter1.updateData(data.list)
    }
}